// SCENARIO SCRIPT

// This is the special script for your entire scenario. It contains
// special encounters and code accessable from anywhere in the scenario. it also
// contains the code that initializes important special things in the
// scenario (like shops and names and descriptions of special items).

// You can create your own states, but you should give all of them numbers greater than
// or equal to 10.

beginscenarioscript;

variables;

int day1,day2,choice,i,j,x,tick1,tick2,tick3,day5,day6,day4,user,userx,usery,n,q,p;

body;

beginstate LOAD_SCEN_STATE;

// *** Quests ***

	init_quest(1,"Get rid of bandit leader","Mayor Ruth in Voughton wants you to kill the bandit leader in the sewers of Voughton.");
	init_quest(2,"Find the empire liaison","Mayor Ruth in Voughton asked you to find the empire liaison. He was kidnapped in the middle of the night.");
	init_quest(3,"Get the important book","Flanagan, a wizard in Pleasantville, has asked you to go to the Senarti Fort and bring his book back.");
	init_quest(4,"Find the wand","Benthol, and old mage in Voughton, collects antiques. He wants a certain wand in tel-Dakrach, for wich he in turn will give you something special.");
	init_quest(5,"Find emperor Thralni","Benthol says, that emperor Thralni will probably want revenge. He wants you to find him and stop him."); //X Not used
	init_quest(6,"Honor the spirit of Dakrack","When you tried to take the scepters from Tel-Dakrach, a shade appeared and said he'll curse you forever, if you don't do the quest.");
	init_quest(7,"Find clues in Stracton","Commander Johnson in Fort Filbert asked you to search for clues in the village that was destroyed and where you got wounded: Stracton.");
	init_quest(8,"Wipe out Senarti fort","Mayor Ruth said that you can help her with the Senarti problem, by wiping out the Senarti Fort.");
	init_quest(9,"Destroy Senarti origin","Mayor Ruth asked if you could find out how and where the Senarti are created. Maybe you can also destroy it.");
	init_quest(10,"Kill the one responsible","You destroyed the Senarti Creation Halls. Now Mayor Ruth of Voughton wants you to find and kill the one responsible.");
	init_quest(11,"Investigate Fort Filbert","Mayor Arbuckle of Filberton asked you to investigate Fort Filbert. Bring him anything usefull you can find.");
	init_quest(12,"Find wife","The wife of one of the officials in the empire HQ was kidnapped. Try to find her. All the official knows, is that the Senarti took her to their fort.");
	init_quest(13,"Get red hydra heads","Redrick in Filberton wants you to get three red hydra heads for him. His reward will be priceless, at least that is what he says.");
	init_quest(14,"Go see Summertown","Mayor Arbuckle of Filberton wants you to take a look at Summertown, a ruined city in the middle of Riverrod. Then come back to him.");

// *** Special items ***

	init_special_item(0,"Note","The small note, gotten from the Empire liaison in Voughton, will enable you to look at the archives in the Empire HQ.");
	init_special_item(1,"Suspicious Senarti note","This is a small leather bounded scroll. It sits in some sort of leather tube, with one opening on one side. You found it in commanders Johnson's office.");
	init_special_item(2,"Old spell book","It's a heavy, old, dusty book. When you try to open it, you burn your hands slightly on it's lock. You can't open it.");
	init_special_item(3,"The real scepter","An old scepter glows slightly in your hands. You really don't know what to do with it.");
	init_special_item(4,"The false scepter","You are holding an old scepter. It does nothing. It looks rather worthless.");
	init_special_item(5,"Senarti instructions","The scroll seems quite new. Written on it are runes you can't read. Maybe a wizard could?");
	init_special_item(6,"Rusten key","This small key is all rusty. When you whipe off the rust, however, a silver key with elegant patterns is what you hold in your hand.");
	init_special_item(7,"Manual","This leather bounded book has all kinds of instructions in it. It looks very useful to you.");
	init_special_item(8,"Iron key","This small shining key was lying in a small box in some storage room. You don't know what it's really for.");
	init_special_item(9,"Suspicious Senarti note","This is a small leather bounded scroll. It sits in some sort of leather tube, with one opening on one side. You found it in the bandit's leader desk under Voughton.");
	init_special_item(10,"Strange herbs","You found these herbs in a box in a small storage room at Thralni's castle laboratories. They look like energy herbs, but they aren't.");
	init_special_item(11,"Strange herbs","You found these herbs in a tunnel, leading away of Thralni's testing halls. They look like energy herbs, but they aren't.");
	init_special_item(12,"Strange herbs","You found these herbs in a tunnel, leading away of Thralni's testing halls. They look like energy herbs, but they aren't.");
	init_special_item(13,"Empire order","You got this leather bounded scroll from General Flamington. It should enable you to enter the Riverrod crystal mine.");

// *** Special abilities ***

	init_special_abil(0,"Special potion making",10);

break;

beginstate START_SCEN_STATE;

	// Boats
	
	create_boat(0,38,29,5,0);
	create_boat(1,38,33,7,0);
	create_boat(2,38,38,5,0);
	create_boat(3,38,40,6,0);

	// Initialize a few shops.
	
// Shops in warriors grove (Out of scenario)
	
	// Shop 0 - armor
	add_item_to_shop(0,25,25);
	add_item_to_shop(0,26,20);
	add_item_to_shop(0,30,20);
	add_item_to_shop(0,31,10);
	add_item_to_shop(0,35,10);
	add_item_to_shop(0,121,15);
	add_item_to_shop(0,122,15);
	add_item_to_shop(0,126,3);
	add_item_to_shop(0,131,2);
	add_item_to_shop(0,111,15);
	add_item_to_shop(0,16,10);
	add_item_to_shop(0,136,10);
	add_item_to_shop(0,137,10);
	add_item_to_shop(0,141,5);
	
	// Shop 1 - weapons
	add_item_to_shop(1,45,25);
	add_item_to_shop(1,46,20);
	add_item_to_shop(1,50,15);
	add_item_to_shop(1,51,10);
	add_item_to_shop(1,55,5);
	add_item_to_shop(1,65,20);
	add_item_to_shop(1,66,10);
	add_item_to_shop(1,70,5);
	
	// Shop 2 - tools
	add_item_to_shop(2,170,500);
	add_item_to_shop(2,171,500);
	add_item_to_shop(2,172,30);
	add_item_to_shop(2,174,500);
	add_item_to_shop(2,177,500);
	
	// Shop 3 - missiles
	add_item_to_shop(3,85,500);
	add_item_to_shop(3,86,10);
	add_item_to_shop(3,90,10);
	add_item_to_shop(3,95,3);
	add_item_to_shop(3,100,20);
	add_item_to_shop(3,101,10);
	add_item_to_shop(3,105,10);

	// Shop 4 - potions
	add_item_to_shop(4,220,4);
	add_item_to_shop(4,221,3);
	add_item_to_shop(4,222,3);
	add_item_to_shop(4,223,2);

	// Shop 5 - food
	add_item_to_shop(5,4,500);
	add_item_to_shop(5,6,500);
	add_item_to_shop(5,7,500);
	
// Shops in pleasant ville
	
	// Shop 6 - potions
	add_item_to_shop(6,226,3);
	add_item_to_shop(6,227,2);
	add_item_to_shop(6,228,4);
	add_item_to_shop(6,231,6);
	
	// Shop 7 - spells
	add_item_to_shop(7,3003,3);
	add_item_to_shop(7,3005,3);
	add_item_to_shop(7,3007,2);
	add_item_to_shop(7,3009,2);
	add_item_to_shop(7,3010,1);
	
	// Shop 8 - weapons
	add_item_to_shop(8,46,5);
	add_item_to_shop(8,47,3);
	add_item_to_shop(8,51,4);
	add_item_to_shop(8,56,5);
	add_item_to_shop(8,60,8);
	add_item_to_shop(8,66,2);
	add_item_to_shop(8,72,5);
	add_item_to_shop(8,75,6);
	
	// Shop 9 - tools and supplies
	add_item_to_shop(9,79,6);
	add_item_to_shop(9,82,10);
	add_item_to_shop(9,83,12);
	add_item_to_shop(9,109,4);
	add_item_to_shop(9,158,6);
	add_item_to_shop(9,159,7);
	add_item_to_shop(9,161,15);
	add_item_to_shop(9,164,3);
	add_item_to_shop(9,170,16);
	add_item_to_shop(9,171,12);
	add_item_to_shop(9,172,11);
	add_item_to_shop(9,174,17);
	add_item_to_shop(9,177,14);
	
	
	// Shop 10 - food
	add_item_to_shop(10,4,500);
	add_item_to_shop(10,5,500);
	add_item_to_shop(10,6,500);
	add_item_to_shop(10,7,500);	

// Shops in Voughton

	// Shop 11 - food
	add_item_to_shop(11,4,500);
	add_item_to_shop(11,5,500);
	add_item_to_shop(11,6,500);
	add_item_to_shop(11,7,500);	
	add_item_to_shop(11,8,500);
	add_item_to_shop(11,10,500);
	add_item_to_shop(11,11,500);
	add_item_to_shop(11,12,500);
	add_item_to_shop(11,397,500);
	add_item_to_shop(11,398,500);
	add_item_to_shop(11,399,500);

	// Shop 12 - Potions
	add_item_to_shop(12,220,5);
	add_item_to_shop(12,221,6);
	add_item_to_shop(12,223,3);
	add_item_to_shop(12,224,8);
	add_item_to_shop(12,230,2);

	// Shop 13 - Armor
	add_item_to_shop(13,27,6);
	add_item_to_shop(13,31,4);
	add_item_to_shop(13,35,5);
	add_item_to_shop(13,36,3);
	add_item_to_shop(13,40,2);
	
	// Shop 14 - Clothing
	add_item_to_shop(14,13,7);
	add_item_to_shop(14,14,9);
	add_item_to_shop(14,15,5);
	add_item_to_shop(14,17,3);
	add_item_to_shop(14,18,10);
	add_item_to_shop(14,19,4);
	add_item_to_shop(14,21,6);
	
	// Shop 15 - Dresses
	add_item_to_shop(15,23,15);
	
	// Shop 16 - Weapons
	add_item_to_shop(16,45,5);
	add_item_to_shop(16,47,6);
	add_item_to_shop(16,51,2);
	add_item_to_shop(16,55,7);
	add_item_to_shop(16,56,3);
	
// Empire HQ

	// Shop 17 - potion recipes
	add_item_to_shop(17,4000,-1);
	add_item_to_shop(17,4001,-1);
	add_item_to_shop(17,4002,-1);
	add_item_to_shop(17,4004,-1);
	add_item_to_shop(17,4010,-1);

// Filberton

	// Shop 18 - spells (mage)
	add_item_to_shop(18,2000,6);
	add_item_to_shop(18,2001,6);
	add_item_to_shop(18,2002,6);
	add_item_to_shop(18,2004,6);
	add_item_to_shop(18,2006,5);
	add_item_to_shop(18,2007,5);
	add_item_to_shop(18,2008,5);
	add_item_to_shop(18,2009,4);
	add_item_to_shop(18,2010,4);
	add_item_to_shop(18,2012,4);
	add_item_to_shop(18,2013,3);
	add_item_to_shop(18,2014,3);
	add_item_to_shop(18,2015,2);
	add_item_to_shop(18,2017,1);
	add_item_to_shop(18,2018,1);
	
	// Shop 19 - potion recipes
	add_item_to_shop(19,4000,5);
	add_item_to_shop(19,4003,6);
	add_item_to_shop(19,4005,2);
	add_item_to_shop(19,4006,7);
	add_item_to_shop(19,4012,3);
	
	// Shop 20 - spells (priest)
	add_item_to_shop(20,3000,6);
	add_item_to_shop(20,3001,6);
	add_item_to_shop(20,3002,6);
	add_item_to_shop(20,3004,6);
	add_item_to_shop(20,3005,6);
	add_item_to_shop(20,3006,5);
	add_item_to_shop(20,3007,5);
	add_item_to_shop(20,3008,5);
	add_item_to_shop(20,3009,4);
	add_item_to_shop(20,3010,4);
	add_item_to_shop(20,3011,4);
	add_item_to_shop(20,3013,3);
	add_item_to_shop(20,3015,2);
	add_item_to_shop(20,3016,2);
	add_item_to_shop(20,3017,1);
	
	// Shop 21 - stuff
	add_item_to_shop(21,172,1);
	add_item_to_shop(21,76,1);
	add_item_to_shop(21,205,1);
	add_item_to_shop(21,55,2);
	add_item_to_shop(21,44,1);
	add_item_to_shop(21,31,1);
	add_item_to_shop(21,81,1);
	add_item_to_shop(21,220,2);
	add_item_to_shop(21,13,7);
	add_item_to_shop(21,14,9);
	
	// Shop 22 - armor
	add_item_to_shop(22,25,25);
	add_item_to_shop(22,26,20);
	add_item_to_shop(22,30,20);
	add_item_to_shop(22,31,10);
	add_item_to_shop(22,35,10);
	add_item_to_shop(22,121,15);
	add_item_to_shop(22,122,15);
	add_item_to_shop(22,126,3);
	add_item_to_shop(22,131,2);
	add_item_to_shop(22,111,15);
	add_item_to_shop(22,16,10);
	add_item_to_shop(22,136,10);
	add_item_to_shop(22,137,10);
	add_item_to_shop(22,141,5);
	
	// Shop 23 - weapons and archery
	add_item_to_shop(23,100,25);
	add_item_to_shop(23,101,20);
	add_item_to_shop(23,102,15);
	add_item_to_shop(23,105,10);
	add_item_to_shop(23,106,5);
	add_item_to_shop(23,90,20);
	add_item_to_shop(23,91,10);
	add_item_to_shop(23,96,5);
	
	// Shop 24 - poleweapons
	add_item_to_shop(24,65,19);
	add_item_to_shop(24,66,18);
	add_item_to_shop(24,67,16);
	add_item_to_shop(24,70,20);
	add_item_to_shop(24,71,10);
	add_item_to_shop(24,72,9);
	add_item_to_shop(24,75,10);
	add_item_to_shop(24,76,5);
	
	// Shop 25 - stuff
	add_item_to_shop(25,195,5);
	add_item_to_shop(25,186,3);
	add_item_to_shop(25,231,2);
	add_item_to_shop(25,228,2);
	add_item_to_shop(25,232,2);
	add_item_to_shop(25,233,1);
	add_item_to_shop(25,210,3);
	add_item_to_shop(25,244,4);
	add_item_to_shop(25,245,4);
	add_item_to_shop(25,271,1);
	add_item_to_shop(25,293,1);
	add_item_to_shop(25,296,1);
	

	// This message whenever the scenario starts, but only when its started for the first time.
	message_dialog("The scenario can be played with almost every party configuration, but things will get very weird if you don't have at least four players in the party. You can play with less, but things will get very weird.","Also, try hard to ALWAYS have a character in the first slot of your party. Otherwise, in certain cutscenes, things will get weird or wont function at all. Thank you.");
	message_dialog("If you haven't read the accompanied readme file, I ask you to do so now. There are some known bugs which I described in the readme file, which, if you know about them, will make life easier for you.","");

break;

beginstate START_STATE;

// The thing with appointment mayor of Filberton

if (get_flag(28,0) == 1) {
		day1 = (get_flag(250,4));
		
		if (what_day_of_scenario() > (day1 + 1)) {
				set_flag(28,0,2);
				print_str_color("You missed your appointment with mayor Arbuckle of Filberton.",3);
				}

		if (get_flag(200,2) == 0) {
				day1 = get_flag(250,4);
				if (what_day_of_scenario() == (day1 + 1)) {
						set_flag(200,2,1);
						print_str_color("Today you have an appointment with mayor Arbuckle of Filberton.",3);
						}
				}
		}

// The arrest of commander Johnson in Fort Filbert

if (get_flag(28,1) == 2) {
		if (get_flag(12,11) == 0) {
				day2 = get_flag(250,5);
				if (what_day_of_scenario() == (day2 + 2)) {
						set_flag(12,11,1);
						}
				}
		}

// The destruction of the empire HQ and consequences

if (get_flag(12,11) != 1) {
		if (get_flag(41,0) == 0) {
				if (get_flag(121,0) == 0) {
						if (what_day_of_scenario() >= 10) {
										set_flag(121,0,1);
										set_town_visibility(18,1);
										message_dialog("As you walk onwards, you suddenly hear shouting and clanging of armor and weapons. The sounds come from the direction of the Empire headquarters! It may be a very wise decision to see what's happening.","");
								}
						}
				}
		}

// Sheep disappearing in town 16

day5 = what_day_of_scenario();

if (day5 >= 120) {
		day4 = (day5 % 12);
		set_state_continue(13);
		}
break;

// Place your own states below. Give each a number at least 10.


// States 10 & 11: special ability 0

beginstate 10;
change_custom_abil_uses(who_used_custom_abil(),0,1); 

if (has_special_item(10) == 1) {
		x = 10;
		set_state_continue(11);
		}
	if (has_special_item(11) == 1) {
			x = 11;
			set_state_continue(11);
			}
		if (has_special_item(12) == 1) {
				x = 12;
				set_state_continue(11);
				}
			print_str_color("You don't have the right ingredients.",3);
break;

beginstate 11;
if (has_item(184) == 1) {
		print_str_color("You make an explosive potion.",3);
		run_animation_sound(8);
		change_spec_item(x,-1);
		
		j = 0;
		while (j < 4) {	
		char_give_item(j,484);
		if (char_has_item(j,484) == 1) {
				end();
				}
			j = j + 1;
			}
		}
	print_str_color("You don't have mortar and pestle to make the potion with.",3);
break;

beginstate 12;
	small_draw_pic_dialog(551,"The note says the following:");
break;

beginstate 13;
	set_flag(250,3,day4);
	set_state(START_STATE)
break;

beginstate 14;
user = who_used_custom_item();

userx = char_loc_x(user);
usery = char_loc_y(user);

		if (get_terrain((userx - 1),(usery - 2)) != 0) {
				message_dialog("There is not enough space to place the summoned monsters. try again when the specific place where the monsters will appear is free.","");
				end();
				}
		
		if (get_terrain(userx,(usery - 2)) != 0) {
				message_dialog("There is not enough space to place the summoned monsters. try again when the specific place where the monsters will appear is free.","");
				end();
				}
		
		if (get_terrain((userx + 1),(usery - 2)) != 0) {
				message_dialog("There is not enough space to place the summoned monsters. try again when the specific place where the monsters will appear is free.","");
				end();
				}
		
		if (char_on_spot((userx - 1),(usery - 2)) != -1) {
				message_dialog("There is not enough space to place the summoned monsters. try again when the specific place where the monsters will appear is free.","");
				end();
				}
		
		if (char_on_spot(userx,(usery - 2)) != -1) {
				message_dialog("There is not enough space to place the summoned monsters. try again when the specific place where the monsters will appear is free.","");
				end();
				}
		
		if (char_on_spot((userx + 1),(usery - 2)) != -1) {
				message_dialog("There is not enough space to place the summoned monsters. try again when the specific place where the monsters will appear is free.","");
				end();
				}

		if (char_ok(86) == 0) {
				n = 86;
				set_state_continue(16);
				}
		if (char_ok(87) == 0) {
				n = 87;
				set_state_continue(16);
				}
		if (char_ok(88) == 0) {
				n = 88;
				set_state_continue(16);
				}
		if (char_ok(89) == 0) {
				n = 89;
				set_state_continue(16);
				}
		if (char_ok(90) == 0) {
				n = 90;
				set_state_continue(16);
				}
		if (char_ok(91) == 0) {
				n = 91;
				set_state_continue(16);
				}
		if (char_ok(92) == 0) {
				n = 92;
				set_state_continue(16);
				}
		if (char_ok(93) == 0) {
				n = 93;
				set_state_continue(16);
				}
		if (char_ok(94) == 0) {
				n = 94;
				set_state_continue(16);
				}
		if (char_ok(95) == 0) {
				n = 95;
				set_state_continue(16);
				}
		if (char_ok(96) == 0) {
				n = 96;
				set_state_continue(16);
				}
		if (char_ok(97) == 0) {
				n = 97;
				set_state_continue(16);
				}
		if (char_ok(98) == 0) {
				n = 98;
				set_state_continue(16);
				}
		if (char_ok(99) == 0) {
				n = 99;
				set_state_continue(16);
				}
		if (char_ok(100) == 0) {
				n = 100;
				set_state_continue(16);
				}
		if (char_ok(101) == 0) {
				n = 101;
				set_state_continue(16);
				}
		if (char_ok(102) == 0) {
				n = 102;
				set_state_continue(16);
				}
		if (char_ok(103) == 0) {
				n = 103;
				set_state_continue(16);
				}
		if (char_ok(104) == 0) {
				n = 104;
				set_state_continue(16);
				}
		if (char_ok(105) == 0) {
				n = 105;
				set_state_continue(16);
				}
		if (char_ok(106) == 0) {
				n = 106;
				set_state_continue(16);
				}
		if (char_ok(107) == 0) {
				n = 107;
				set_state_continue(16);
				}
		if (char_ok(108) == 0) {
				n = 108;
				set_state_continue(16);
				}
		if (char_ok(109) == 0) {
				n = 109;
				set_state_continue(16);
				}
		if (char_ok(110) == 0) {
				n = 110;
				set_state_continue(16);
				}
		if (char_ok(111) == 0) {
				n = 111;
				set_state_continue(16);
				}
		if (char_ok(112) == 0) {
				n = 112;
				set_state_continue(16);
				}
		if (char_ok(113) == 0) {
				n = 113;
				set_state_continue(16);
				}
		if (char_ok(114) == 0) {
				n = 114;
				set_state_continue(16);
				}
		if (char_ok(115) == 0) {
				n = 115;
				set_state_continue(16);
				}
		if (char_ok(116) == 0) {
				n = 116;
				set_state_continue(16);
				}
			message_dialog("There are too many mosters in this town to summon Redrick and his friends. Either kill some monsters, or do without him. Three monsters have to die before you can try to summon Redrick","");
break;

beginstate 15;
	small_draw_pic_dialog(552,"This is a small map of Thralni's castle");
break;

beginstate 16;
		place_monster((userx - 1),(usery - 2),16,0);
		put_effect_on_char(n,10,6,0);
		set_attitude(n,3);
		run_animation_sound(61);

		p = n + 1;
		
		char_ok(n);

		place_monster((userx),(usery - 2),20,0);
		put_effect_on_char(p,10,6,0);
		set_attitude(p,3);
		run_animation_sound(61);
		
		q = p + 1;
		
		char_ok(n);

		place_monster((userx + 1),(usery - 2),16,0);
		put_effect_on_char(q,10,6,0);
		set_attitude(q,3);
		run_animation_sound(61);
		
		message_dialog("You use the horn, and redrick appears, together with two friendly mages. he turns to you and says: _Glad you called me! this battle seems worthwhile!_","When he turns around again, ready to fight, your horn is gone! You wouldn't be able to summon redrick again. Hopefully you did the right thing using the horn in this battle.");
	
		take_all_of_item(489);
break;